<template>
  <el-dialog
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :destory-on-close="true"
    :title="title"
    :visible.sync="dialogFormVisible"
    width="65%"
    @close="close"
  >
    <el-form ref="form" label-width="200px" :model="form" :rules="rules">
      <el-form-item label="姓名" prop="name">
        {{ form.name }}
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        {{ form.phone }}
      </el-form-item>
      <el-form-item label="身份证正面照片" prop="idCardFront">
        <el-input v-model="form.idCardFront" style="display: none" />
        <el-upload
          v-model="form.idCardFront"
          action="https://star.gengduoke.com/adminapi/file/upload"
          :before-upload="beforeAvatarUploadtwo"
          class="avatar-uploader"
          disabled
          :headers="{
            'X-Token': token,
          }"
          :on-success="handleAvatarSuccesstwo"
          :show-file-list="false"
        >
          <img v-if="imageUrltwo" class="avatar" :src="imageUrltwo" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="身份证反面照片" prop="idCardReverse">
        <el-input v-model="form.idCardReverse" style="display: none" />
        <el-upload
          v-model="form.idCardReverse"
          action="https://star.gengduoke.com/adminapi/file/upload"
          :before-upload="beforeAvatarUpload"
          class="avatar-uploader"
          disabled
          :headers="{
            'X-Token': token,
          }"
          :on-success="handleAvatarSuccess"
          :show-file-list="false"
        >
          <img v-if="imageUrl" class="avatar" :src="imageUrl" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>

      <el-form-item label="身份证号码" prop="ofEnterprise">
        {{ form.idCardNum }}
      </el-form-item>
      <el-form-item label="审核状态" prop="checkValue">
        <el-select v-model="form.checkValue" placeholder="请选择审核状态">
          <el-option
            v-for="item in options1"
            :key="item.id"
            :label="item.creClasName"
            :value="item.id"
            @click.native="optosall(item)"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="form.checkValue == 0"
        label="驳回原因"
        prop="rejectReason"
      >
        <el-input v-model="form.rejectReason" placeholder="请输入驳回原因" />
      </el-form-item>
    </el-form>
    <el-button class="baocun" size="medium" type="primary" @click="save">
      保存
    </el-button>
  </el-dialog>

  <!-- 增加 -->
</template>

<script>
  /* eslint-disable*/
  import { realcheck } from '@/api/shiming'

  export default {
    name: 'search',

    data() {
      return {
        token: '',
        imageUrl: '',
        imageUrltwo: '', //身份证正
        options1: [
          {
            id: 1,
            creClasName: '审核通过',
          },
          {
            id: 0,
            creClasName: '审核未通过',
          },
        ], //审核状态
        form: {
          checkValue: '', //审核的结果0未通过1通过
          rejectReason: '', //审核未通过时驳回原因
          starUserId: 1, //移动端用户id 传过来的id
          beCheckedId: 1, //被审核的数据的id 选项的id
        },
        activated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.play()
        },
        deactivated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.pause()
        },

        rules: {
          rejectReason: [
            { required: true, trigger: 'blur', message: '请输入驳回原因' },
          ],
          checkValue: [
            { required: true, trigger: 'change', message: '请选择审核状态' },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '处理'
          this.form = Object.assign({}, row)
          this.imageUrl = row.idCardReverse
          this.imageUrltwo = row.idCardFront
          this.form.authEnterprise = String(row.authEnterprise)
          this.dialogFormVisible = true
          this.form.starUserId = row.id
          // this.form.beCheckedId = row.id
          console.log(this.form.starUserId)
          // console.log(this.form.beCheckedId)
        }
      },
      optosall(e) {
        this.form.checkValue = e.id
        console.log(this.form.checkValue)
      },
      close() {
        let userId = this.form.userId
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        if (!this.form.id) {
          this.form.userId = userId
        }
        this.dialogFormVisible = false
        this.imageUrl = ''
        // this.form = ''
      },
      save() {
        const msg = realcheck(this.form)
        msg.then((res) => {
          console.log(res)
          this.$emit('fetch-data')
          this.close()
          msg.then((res) => {
            this.$baseMessage(res.msg, 'success', 'vab-hey-message-success')
          })
        })
      },
      beforeAvatarUploadtwo(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!')
        }
        return true
      },
      handleAvatarSuccesstwo(res, file, fileList) {
        this.imageUrltwo = URL.createObjectURL(file.raw)
        this.form.moka = res.data
      },
      handleAvatarSuccess(res, file, fileList) {
        this.imageUrl = URL.createObjectURL(file.raw)
        console.log(res)
        this.form.idCardReverse = res.data
      },
      handleAvatarSuccesstwo(res, file, fileList) {
        this.imageUrltwo = URL.createObjectURL(file.raw)
        this.form.idCardFront = res.data
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!')
        }
        return true
      },
      beforeAvatarUploadtwo(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!')
        }
        return true
      },
      nickNameChange() {
        this.$forceUpdate()
      },
    },
  }
</script>
<style>
  .avatar-uploader .el-upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    width: 178px;
    height: 178px;
    font-size: 28px;
    line-height: 178px;
    color: #8c939d;
    text-align: center;
  }
  .avatar {
    display: block;
    width: 178px;
    height: 178px;
  }
  .baocun {
    width: 100%;
    height: 100%;
  }
</style>
